const db = uniCloud.database();
const cmd = db.command;
const selfUtils = require('self-utils')
module.exports = {
  _before: async function() { // 通用预处理器
    this.params = this.getParams()[0]
    this.userInfo = await selfUtils.getUserInfo(this)
  },
  //获取sku的所有规格信息
  async get() {
    return await db.collection("ly-mall-sku").get()
  },
  //新增规格
  async add() {
    this.params.checked = false;
    return await db.collection("ly-mall-sku").add(this.params)
  },
  //修改规格
  async updateChild(id, obj) {
    obj.checked = false
    return await db.collection("ly-mall-sku").doc(id).update({
      children: cmd.push([obj])
    })
  }
}